﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TestTextGenerator : MonoBehaviour
{
    string mStr;
    int[,] mArr;

    bool mIsMouseDown;


    void Awake()
    {
        mStr = "";
        mArr = new int[28, 28];
    }

    void OnGUI()
    {
        if (Event.current.type == EventType.MouseDown)
        {
            mIsMouseDown = true;
        }
        else if (Event.current.type == EventType.MouseUp)
        {
            mIsMouseDown = false;
        }

        for (int y = 0; y < 28; y++)
        {
            for (int x = 0; x < 28; x++)
            {
                var cacheColor = GUI.color;
                GUI.color = mArr[x, y] == 1 ? Color.red : cacheColor;

                var rect = new Rect(x * 15, y * 15, 14, 14);
                GUI.Button(rect, " ");

                if (rect.Contains(Event.current.mousePosition) && mIsMouseDown)
                {
                    mArr[x, y] = 1;
                }

                GUI.color = cacheColor;
            }
        }

        if (GUI.Button(new Rect(600, 0, 100, 50), "Reset"))
        {
            for (int y = 0; y < 28; y++)
                for (int x = 0; x < 28; x++)
                    mArr[x, y] = 0;
        }

        if (GUI.Button(new Rect(600, 100, 100, 50), "Generate"))
        {
            mStr = "";
            for (int y = 0; y < 28; y++)
                for (int x = 0; x < 28; x++)
                    mStr += mArr[x, y] + ",";

            mStr = mStr.TrimEnd(',');

            GUIUtility.systemCopyBuffer = mStr;
            Debug.Log("Copyed to clipboard! " + mArr.Length);
        }

        GUI.TextArea(new Rect(600, 200, 100, 200), mStr);
    }
}
